package com.sfh.cpc.com.widget;

import android.content.Context;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.sfh.cpc.com.BaseAppContent;
import com.sfh.cpc.com.R;
import com.sfh.cpc.com.entity.EMass;
import com.sfh.cpc.com.entity.EUser;
import com.sfh.lib.AppCacheManager;

/**
 * 功能描述:
 *
 * @author SunFeihu 孙飞虎
 * @date 2019/5/20
 */
public class VIPMassView extends LinearLayout {
    public VIPMassView(Context context) {
        super(context);
        init();
    }

    public VIPMassView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public VIPMassView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    ImageView vip;
    ImageView iv_age;
    ImageView iv_age2;
    ImageView iv_create;
    void init() {
        setGravity(Gravity.CENTER);
        inflate(getContext(), R.layout.widget_layout_vip_mass, this);
        vip = findViewById(R.id.iv_vip);
        iv_age = findViewById(R.id.iv_age);
        iv_age2  = findViewById(R.id.iv_age2);
        iv_create = findViewById(R.id.iv_create);
    }

    public void showVIP(EMass mass) {
        if (TextUtils.equals("1", mass.getNoteVip())) {
            vip.setVisibility(VISIBLE);
        } else {
            vip.setVisibility(GONE);
        }

        final EUser user = AppCacheManager.getCache(BaseAppContent.USER, EUser.class);
        if (user != null && user.getUserId() == mass.getMassUserId()){
            iv_create.setVisibility(VISIBLE);
        }else{
            iv_create.setVisibility(GONE);
        }
        int age = (int) (mass.getNoteSize() / 5 + (mass.getNoteSize() % 5 > 0 ? 1 : 0));
        if (age > 20){
            iv_age2.setVisibility(VISIBLE);
            iv_age.setVisibility(GONE);
            iv_age2.setImageResource(getImageView(age));
        }else{
            iv_age2.setVisibility(GONE);
            iv_age.setVisibility(VISIBLE);
            iv_age.setImageResource(getImageView(age));
        }

    }

    private int getImageView(int size) {
        switch (size) {
            case 0:
            case 1:
                return R.drawable.lv_1;
            case 2:
                return R.drawable.lv_2;
            case 3:
                return R.drawable.lv_3;
            case 4:
                return R.drawable.lv_4;
            case 5:
                return R.drawable.lv_5;
            case 6:
                return R.drawable.lv_6;
            case 7:
                return R.drawable.lv_7;
            case 8:
                return R.drawable.lv_8;
            case 9:
                return R.drawable.lv_9;
            case 10:
                return R.drawable.lv_10;
            case 11:
                return R.drawable.lv_11;
            case 12:
                return R.drawable.lv_12;
            case 13:
                return R.drawable.lv_13;
            case 14:
                return R.drawable.lv_14;
            case 15:
                return R.drawable.lv_15;
            case 16:
                return R.drawable.lv_16;
            case 17:
                return R.drawable.lv_17;
            case 18:
                return R.drawable.lv_18;
            case 19:
                return R.drawable.lv_19;
            case 20:
                return R.drawable.lv_20;
            case 21:
                return R.drawable.lv_21;
            case 22:
                return R.drawable.lv_22;
            case 23:
                return R.drawable.lv_23;
            case 24:
                return R.drawable.lv_24;
            case 25:
                return R.drawable.lv_25;
            case 26:
                return R.drawable.lv_26;
            case 27:
                return R.drawable.lv_27;
            case 28:
                return R.drawable.lv_28;
            case 29:
                return R.drawable.lv_29;
            case 30:
                return R.drawable.lv_30;
            case 31:
                return R.drawable.lv_31;
            case 32:
                return R.drawable.lv_32;
            case 33:
                return R.drawable.lv_33;
            case 34:
                return R.drawable.lv_34;
            case 35:
                return R.drawable.lv_35;
            case 36:
                return R.drawable.lv_36;
            case 37:
                return R.drawable.lv_37;
            case 38:
                return R.drawable.lv_38;
            case 39:
                return R.drawable.lv_39;
            case 40:
                return R.drawable.lv_40;
            default:
                return R.drawable.lv_40;
        }
    }
}
